Ext.define('component.customer.cusGenPanel', {
	extend : 'Ext.form.Panel',
	initComponent:function(){
	
	var gridStoreGg = Ext.create('Ext.data.Store', {
        fields: ["id","customerName","customerPhone", "followTime"
                 , "followMode" , "followContent","followType","userName","nextFollowTime","recordUrl","callStatus"],
        pageSize: 10,  //页容量5条数据
        //是否在服务端排序 （true的话，在客户端就不能排序）
        remoteSort: false,
        proxy: {
            type: 'ajax',
            url: jypath+'/customer/follow/list',
            actionMethods: { read: 'POST' },
            reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
                type: 'json', //返回数据类型为json格式
                root: 'rows',  //数据
                totalProperty: 'total' //数据总条数
            }
        },
        autoLoad: true  //即时加载数据
    });
	
	gridStoreGg.on("beforeload",function(){
        Ext.apply(gridStoreGg.proxy.extraParams,{customerId:customerId});
    });
	
	var gridGg = Ext.create('Ext.grid.Panel', {
		id:"gridStoreList",
		minHeight:600,
        store: gridStoreGg,
        columnLines: true,
        columns: [
//                  {
//            text     : '客户名称', 
//            dataIndex: 'customerName'
//        },
        {
            text     : '手机',
            dataIndex: 'customerPhone'
        },{
            text: '跟进时间',
            dataIndex: 'followTime',
            renderer:function(value){
            	return Ext.Date.format(new Date(value),'Y-m-d G:i:s');
            }
        },{
            text: '提醒时间',
            dataIndex: 'nextFollowTime',
            renderer:function(value){
            	if(value)
            	return Ext.Date.format(new Date(value),'Y-m-d G:i:s');
            }
        },{
            text     : '跟进方式',
            dataIndex: 'followMode',
            renderer : function(val) {
                if (val == 1) {
                    return '来电';
                } else if (val == 2) {
                    return '来访';
                }else if (val == 3) {
                    return '信息';
                }else if (val == 4) {
                    return '去电';
                }else if (val == 5) {
                    return '到访';
                }else if (val == 6) {
                    return '系统生成';
                }else if (val == 7) {
                    return '微信';
                }
                return val;
            }
        },{
            text     : '跟进内容',
            dataIndex: 'followContent',
            renderer : function(value,cellmeta,record,rowIndex,columnIndex,store) {
                var rec = record;
                var followId=rec.get("id");
                var followType=rec.get('followType');
                if(followType==2){
                 	var html = '<a href="#" onclick="genJinList('+followId+','+followType+')">图片地址</a>';
                 	return html;
                }else if(followType==3){
                	var html = '<a href="#" onclick="genJinList('+followId+','+followType+')">语音地址</a>';
                 	return html;
                }
                if(value == null){
					value = '';
				}
                return '<span title="'+value+'">'+value+'</span>';
            }
        },{
            text: '电话录音',
            width:'10%',
            renderer : function(value,cellmeta,record,rowIndex,columnIndex,store) {
            	var callStatus=record.get("callStatus");
            	var result="";
            	if(null!=callStatus && callStatus!=""){
            		if(callStatus=="0"){
	            		  result=result+"未取话单";
	            	  }else if(callStatus=="1"){
	            		  var recordUrl = record.get("recordUrl");
	            		  result+='<a href="javascript:previewAudio(\''+recordUrl+'\')">听录音</a>';
	            	  }else if(callStatus=="2"){
	            		  result=result+"未接通";
	            	  }
            	}
                return result;
            }
        },{
            text     : '跟进人',
            dataIndex: 'userName'
        }
        ],
        title: '跟进记录',
        dockedItems: [{  
            xtype: 'pagingtoolbar',  
            store: gridStoreGg,   // GridPanel中使用的数据  
            dock: 'bottom',  
            displayInfo: true,  
            emptyMsg:"没有数据",  
            displayMsg:"显示从{0}条数据到{1}条数据，共{2}条数据"
        }
        ]
    });
	
		
		var defaultConfigg = {
				defaults: {  
		            split: true,    //有分割线  
		            collapsible: true,  //可以折叠
		        },
				items:[gridGg]
		};
		Ext.apply(this,defaultConfigg);
		this.callParent(arguments);
		
	}
});

function previewAudio(url){
	var html='<audio controls="controls"> <source src="'+url+'" type="audio/mpeg"> </audio>';
	var window = Ext.create('Ext.Window', {
        title: "播放录音",
        width: '300',
        height: '80',
        modal : true, 
        //autoScroll:true,
        //maximizable:false,
        layout : 'fit', 
        html:html
    });
	window.show();
}
